package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TestItem;
import com.ruoyi.system.service.ITestItemService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * test_itemController
 * 
 * @author ruoyi
 * @date 2022-09-27
 */
@Controller
@RequestMapping("/system/test_item")
public class TestItemController extends BaseController
{
    private String prefix = "system/test_item";

    @Autowired
    private ITestItemService testItemService;

    @RequiresPermissions("system:test_item:view")
    @GetMapping()
    public String test_item()
    {
        return prefix + "/test_item";
    }

    /**
     * 查询test_item列表
     */
    @RequiresPermissions("system:test_item:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TestItem testItem)
    {
        startPage();
        List<TestItem> list = testItemService.selectTestItemList(testItem);
        return getDataTable(list);
    }

    /**
     * 导出test_item列表
     */
    @RequiresPermissions("system:test_item:export")
    @Log(title = "test_item", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TestItem testItem)
    {
        List<TestItem> list = testItemService.selectTestItemList(testItem);
        ExcelUtil<TestItem> util = new ExcelUtil<TestItem>(TestItem.class);
        return util.exportExcel(list, "test_item数据");
    }

    /**
     * 新增test_item
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("User", testItemService.selectUserName());
        return prefix + "/add";
    }

    /**
     * 新增保存test_item
     */
    @RequiresPermissions("system:test_item:add")
    @Log(title = "test_item", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TestItem testItem)
    {
        return toAjax(testItemService.insertTestItem(testItem));
    }

    /**
     * 修改test_item
     */
    @RequiresPermissions("system:test_item:edit")
    @GetMapping("/edit/{itemId}")
    public String edit(@PathVariable("itemId") Long itemId, ModelMap mmap)
    {
        TestItem testItem = testItemService.selectTestItemByItemId(itemId);
        mmap.put("testItem", testItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存test_item
     */
    @RequiresPermissions("system:test_item:edit")
    @Log(title = "test_item", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TestItem testItem)
    {
        return toAjax(testItemService.updateTestItem(testItem));
    }

    /**
     * 删除test_item
     */
    @RequiresPermissions("system:test_item:remove")
    @Log(title = "test_item", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(testItemService.deleteTestItemByItemIds(ids));
    }
}
